package com.example.admin.activitytest;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

/**
 * Created by admin on 2016/1/27.
 */
public class FirstActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.first_layout);
        Button button1 = (Button) findViewById(R.id.button_1);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String data = "Hello SecondAcitivity";
                Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
                intent.putExtra("extra_data",data);
                startActivityForResult(intent, 1);
            }
        });

    }


    @Override
    protected void onStart(){
        super.onStart();
        Log.d("FirstActivity ", "FirstActivity Start");
    }

    @Override
    protected void onResume(){
        super.onResume();
        Log.d("FirstActivity ","FirstActivity Resume");
    }


    @Override
    protected void onPause(){
        super.onPause();
        Log.d("FirstActivity ","FirstActivity Pause");
    }


    @Override
    protected void onStop(){
        super.onStop();
        Log.d("FirstActivity ","FirstActivity Stop");
    }


    @Override
    protected void onDestroy(){
        super.onDestroy();
        Log.d("FirstActivity ","FirstActivity Destroy");
    }

    @Override
    protected void onRestart(){
        super.onRestart();
        Log.d("FirstActivity ","FirstActivity Restart");
    }


    @Override
    protected void onActivityResult(int requestCode,int resultCode, Intent data){
        switch(requestCode){
            case 1:
                if(resultCode == RESULT_OK){
                    String returnedData = data.getStringExtra("data_return");
                    Log.d("FirstActivity",returnedData);
                }
                break;
            default:
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.add_item:
                Toast.makeText(this, "You clicked Add", Toast.LENGTH_SHORT).show();
                break;
            case R.id.remove_item:
                Toast.makeText(this, "You clicked Remove", Toast.LENGTH_SHORT).show();
                break;
            default:
        }
        return true;
    }



}
